package org.yaukie.frame.util;

import org.yaukie.base.util.DateUtils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 参数增强
 *
 * @author rex
 * @create 2021-12-17 13:41
 * @desc
 **/
public class KettleParamBooster {
    public static final String USER_ID = "\\$\\{USER_ID}";
    public static final String NOW_DATE = "\\$\\{NOW_DATE}";
    public static final String NOW_TIME = "\\$\\{NOW_TIME}";
    public static final String TODAY_BEGIN = "\\$\\{TODAY_BEGIN}";
    public static final String TODAY_END = "\\$\\{TODAY_END}";
    public static final String YESTERDAY_BEGIN = "\\$\\{YESTERDAY_BEGIN}";
    public static final String YESTERDAY_END = "\\$\\{YESTERDAY_END}";
    public static final String BEGIN_OF_DATE = " 00:00:00";
    public static final String END_OF_DATE = " 23:59:59";
    private static final SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd");
    private static final SimpleDateFormat timeFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public static String boost(String param){
        Date date = Calendar.getInstance().getTime();
        Date yesterday = DateUtils.addDays(date, -1);
        
        String nowDate = dateFormatter.format(date);
        String nowTime = timeFormatter.format(date);
        String beginOfToday = nowDate + BEGIN_OF_DATE;
        String endOfToday = nowDate + END_OF_DATE;

        String yesterdayDate = dateFormatter.format(yesterday);
        String beginOfYesterday= yesterdayDate + BEGIN_OF_DATE;
        String endOfYesterday = yesterdayDate + END_OF_DATE;

        return param.replaceAll(NOW_DATE, nowDate)
                .replaceAll(NOW_TIME, nowTime)
                .replaceAll(TODAY_BEGIN, beginOfToday)
                .replaceAll(TODAY_END, endOfToday)
                .replaceAll(YESTERDAY_BEGIN, beginOfYesterday)
                .replaceAll(YESTERDAY_END, endOfYesterday);
    }

    public static void main(String[] args) {
        String message = "${USER_ID}";
        message = message.replaceAll(USER_ID, "99");
        System.out.println(message);
    }
}
